#include "LittleFighter.h"
#include "GameGUI.h"
#include "GameApp.h"
#include "RewardOrb.h"
#include "Sword.h"

//-------------------------------------------------------------------------------------
LittleFighter::LittleFighter(string enemyID) : MirrorBoss(enemyID)
{
	removeType(OBJECT_PLAYER);
	addType(OBJECT_ENEMY);
	addType(OBJECT_LITTLE_FIGHTER);
}
//-------------------------------------------------------------------------------------
LittleFighter::LittleFighter(void) : MirrorBoss("enemies/littlefighter.xml")
{
	removeType(OBJECT_PLAYER);
	addType(OBJECT_ENEMY);
	addType(OBJECT_LITTLE_FIGHTER);
}
//-------------------------------------------------------------------------------------
LittleFighter::~LittleFighter(void)
{
}

void LittleFighter::update(const unsigned long elapsedTime)
{
	updateAi(elapsedTime);
	Player::update(elapsedTime);
}
//-------------------------------------------------------------------------------------
void LittleFighter::updateAi(const unsigned long elapsedTime)
{
	if(getEntity()->getSubEntity(0)->isVisible())
		getEntity()->getSubEntity(0)->setVisible(false);
	//equipment
	if(!sword)
	{
		equipSword();
		sword->setTarget(OBJECT_PLAYER);
	}
	if(!shield)
		equipShield();
	//often used information about position and orientation
	PlayerPtr player(gpApp->mpGameLogic->getCharacter());
	btTransform playerTrans = player->getBody()->getWorldTransform();
	btTransform selfTrans = mpBody->getWorldTransform();
	btVector3 playerDist = getLocalVector(playerTrans.getOrigin());
	float dist = playerDist.length();
	
	if(dist >= 20.f)return;
	//orientation
	if(playerDist.x() <= 0.f)
	{
		lookLeft();
	} else
	{
		lookRight();
	}
	//movement
	if(dist >= 1.5f)
	{
		if(mStates[MOVE_LEFT])
			moveLeft();
		else
			moveRight();
	}
	//combat
	if(dist < 1.5f || !mShootCooldown )
	{
		normalAttack();
	}

	if (mShootCooldown < elapsedTime) mShootCooldown = 0;
	else mShootCooldown -= elapsedTime;
}
//-------------------------------------------------------------------------------------
void LittleFighter::scalePower(const char power)
{
	switch (power)
	{
	case 0:
		break;
	case 1:
		mHealthCap *= 2.0f;
		mHealth = mHealthCap;
		getStats()->setStat(STAT_DAMAGE, getStats()->getStat(STAT_DAMAGE) * 1.5f);
		break;
	case 2:
		mHealthCap *= 3.5f;
		mHealth = mHealthCap;
		getStats()->setStat(STAT_DAMAGE, getStats()->getStat(STAT_DAMAGE) * 2.5f);
		break;
	default:
		break;
	}
}